package mas;

/** Class models a UserAgent which provides useful assessor methods to a
 * Message object
 * 
 * Advanced Java Programming - ICA 2 Middleware 
 * @author Carl Morphet, Matt Constable, Stephen Pammenter
 * Teesside University
 * Created: Mar 20, 2012
 */
public class UserAgent extends MetaAgent
{
    /** An instance variable of the message received */
    private Message message;
    
    /** The identifier of the UserAgent */
    private String name;
    
    /** Default constructor which calls the super constructor of the MetaAgent 
     * class and instantiates the local identifier String
     * 
     * @param name The UserAgents identifying String
     */
    public UserAgent(String name)
    {
        super(name);
        this.name = name;
    }

    /** Method which handles a Message object by passing it to the MetaAgents 
     * msgHandler method and instantiating the message instance variable to the 
     * Message taken as a parameter 
     * 
     * @param m A Message object to be handled
     */
    @Override
    public void msgHandler(Message m)
    {
        super.msgHandler(m);
        this.message = m;
    }
    
    /** Method which sends a message to the portals queue
     * 
     * @param m The message to be sent 
     */
    protected void sendMessage(Message m)
    {
        this.getPortal().msgHandler(m);
    }
    
    /** Accessor method which returns the UserAgents name
     * 
     * @return The String identifier of the UserAgent instance
     */
    protected String getName()
    {
        return name;
    }
    
    /** Accessor method which returns the identifier of the Agent which sent 
     * the message
     * 
     * @return The identifier of the messages sending Agent
     */
    protected String getSender()
    {
        return message.getSender();
    }
    
    /** Accessor method which returns the messages intended recipients identifier 
     * 
     * @return The identifier of the messages intended recipient
     */
    protected String getRecipient()
    {
        return message.getRecipient();
    }
    
    /** Accessor method which returns the ID information of the message
     * 
     * @return The ID information of the message 
     */
    protected String getID()
    {
        return message.getID();
    }
    
    /** Accessor method which returns the messages content
     * 
     * @return The messages content
     */
    protected String getMessageContent()
    {
        return message.getMessage();
    }
    
}